(function() {
	// 查询pump
//	jQuery('.searchPumpBtn').on('click', function() {
//		mainDeviceData.key = jQuery("#pumpkeyword").val();
//		mainDeviceTable.draw();
//	});
	// 撤销查询
	jQuery('.resetPumpBtn').on('click', function() {
		clearQueryMainDeviceData('clearui');
		mainDeviceTable.draw();
	});
	// //主机设备
	var mainDeviceData = {};
	mainDeviceData.key = "";
	var mainDeviceTable;
	jQuery(document).ready(function() {
		mainDeviceTable = jQuery('#mainDeviceTable').DataTable(
										{
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/quotesearch/getpumgpage',
												"data" : function(d) {
													return $.extend({}, d,
															mainDeviceData);
												}
											},
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
														data : 'quoteForeign.customerName',
														render:function(data,type,full,meta){
															if(data == undefined){
																return '<font title=" ">'+'</font>';
															}else{
																if(data == null || data == undefined || data == ""){
																	return data;
																}else{
																	return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
																}
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"...</div>"
															}
														}
													},
													{
														data : 'productName',
														render:function(data,type,full,meta){
															if(data == null || data == undefined || data == ""){
																return data;
															}else{
																return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
															}
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : null,
														render : function(data,type, full,meta) {
																if (data.quote!=null)
																	return data.quote.name;
																else if(data.quoteForeign!=null)
																	return data.quoteForeign.name;
														}
													},
													{
														data : 'productType',
														render:function(data,type,full,meta){
															if(data == null || data == undefined || data == ""){
																return data;
															}else{
																return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
															}
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : 'productModel',
														render:function(data,type,full,meta){
															if(data == null || data == undefined || data == ""){
																return data;
															}else{
																return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
															}
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
//													{
//														data : null,
//														render : function(data,
//																type, full,
//																meta) {
//															var dOut;
//															if (data.isInventory == "1") {
//																dOut = '<td class="center" ><span class="badge label-pill label-success">是</span></td>';
//															} else {
//																dOut = '<td class="center" ><span class="badge label-pill label-danger">否</span></td>';
//															}
//															return dOut;
//														}
//													},
													{
														data : 'unitPrice'
													},
													{
														data : 'number'
													},
													{
														data:'unit'
													},

													{
														data : null,
														render : function(data) {
															   if(data.quote)
																return data.quote.user.empLogin.userName;
																else if(data.quoteForeign)
																	return data.quoteForeign.user.empLogin.userName;
														}
													},
													{
														data : null,
														render : function(data,type, full,meta) {
																if (data.quote!=null)
																	return data.quote.user.saleArea.superiorArea;
																else if(data.quoteForeign!=null)
																	return data.quoteForeign.user.saleArea.superiorArea;
														}
													}, 
													{
														data : null,
														render : function(data) {
																if (data.quote)
																	return moment(data.quote.createTime).format('YYYY/MM/DD');
																else if(data.quoteForeign)
																	return moment(data.quoteForeign.createTime).format('YYYY/MM/DD');
														}
													}
//													{
//														data : 'power'
//													}, {
//														data : 'flowMaterial'
//													}, {
//														data : 'transMedia'
//													}, {
//														data : 'viscosity'
//													}, {
//														data : 'flux'
//													}, {
//														data : 'pumpLift'
//													}, {
//														data : 'temperature'
//													}, {
//														data : 'proportion'
//													}, {
//														data : 'inPressure'
//													}, {
//														data : 'effectiveNPSHA'
//													}, {
//														data : 'mustMPSHA'
//													} 
													],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;
												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$( 'td:eq(0)',
														oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
													k++;
												}
											}
										});
					});
	// 查询pump
	jQuery('.searchPumpBtn').on('click', function() {	
		clearQueryServerData1();
		if(jQuery('#customerName').val().trim())  mainDeviceData.customerName= jQuery('#customerName').val();else mainDeviceData.customerName=null;
		if(jQuery('#productName').val().trim())  mainDeviceData.productName= jQuery('#productName').val();else mainDeviceData.productName=null;
		if(jQuery('#projectName').val().trim())  mainDeviceData.projectName= jQuery('#projectName').val();else mainDeviceData.projectName=null;
		if(jQuery('#productType').val().trim()) 	 mainDeviceData.productType= jQuery('#productType').val();else mainDeviceData.productType=null;
		if(jQuery('#productModel').val().trim()) 	 mainDeviceData.productModel= jQuery('#productModel').val();else mainDeviceData.productModel=null;
		
		if(jQuery('#unitPrice').val().trim()) 	 mainDeviceData.unitPriceStartNum= jQuery('#unitPrice').val();else mainDeviceData.unitPriceStartNum=null;
		if(jQuery('#unitPrice-end').val().trim()) 	 mainDeviceData.unitPriceEndNum= jQuery('#unitPrice-end').val();else mainDeviceData.unitPriceEndNum=null;

		if(jQuery('#number').val().trim()) 	 mainDeviceData.numberStartNum= jQuery('#number').val();else mainDeviceData.numberStartNum=null;
		if(jQuery('#number-end').val().trim()) 	 mainDeviceData.numberEndNum= jQuery('#number-end').val();else mainDeviceData.numberEndNum=null;

		if(jQuery('#userName').val().trim()) 	 mainDeviceData.userName= jQuery('#userName').val();else mainDeviceData.userName=null;
		if(jQuery('#superiorArea').val().trim()) 	 mainDeviceData.superiorArea= jQuery('#superiorArea').val();else mainDeviceData.superiorArea=null;
		if(jQuery('#createTimeStartDate').val().trim()) 	 mainDeviceData.createTimeStartDate= jQuery('#createTimeStartDate').val();else mainDeviceData.createTimeStartDate=null;
		if(jQuery('#createTimeEndDate').val().trim()) 	 mainDeviceData.createTimeEndDate= jQuery('#createTimeEndDate').val();else mainDeviceData.createTimeEndDate=null;
		mainDeviceTable.draw();
//		clearQueryMainDeviceData();
    });
	//清除查询pump关键字
	var clearQueryMainDeviceData=function(option){
	
		if(jQuery('#customerName').val())  mainDeviceData.customerName= null;
		if(jQuery('#productName').val())  mainDeviceData.productName= null;
		if(jQuery('#projectName').val())  mainDeviceData.projectName= null;
		if(jQuery('#productType').val()) 	 mainDeviceData.productType= null;
		if(jQuery('#productModel').val()) 	 mainDeviceData.productModel= null;
		
		if(jQuery('#unitPrice').val()) 	 mainDeviceData.unitPriceStartNum= null;
		if(jQuery('#unitPrice-end').val()) 	 mainDeviceData.unitPriceEndNum= null;
		
		if(jQuery('#number').val()) 	 mainDeviceData.numberStartNum= null;
		if(jQuery('#number-end').val()) 	 mainDeviceData.numberEndNum= null;
		
		if(jQuery('#userName').val()) 	 mainDeviceData.userName= null;
		if(jQuery('#superiorArea').val()) 	 mainDeviceData.superiorArea= null;
		if(jQuery('#createTimeStartDate').val()) 	 mainDeviceData.createTimeStartDate= null;
		if(jQuery('#createTimeEndDate').val()) 	 mainDeviceData.createTimeEndDate= null;
		if(option=='clearui') jQuery('input').val('');
	}
	 //其他设备
	 //查询备件
//	jQuery('.searchReplaceBtn').on('click', function() {
//		serverData1.key = jQuery("#replacekeyword").val();
//		serverTable1.draw();
//	});
	jQuery('.searchReplaceBtn').on('click', function() {
		if(jQuery('#quoteCustomerName').val().trim())  serverData1.customerName= jQuery('#quoteCustomerName').val();else serverData1.customerName=null;
		if(jQuery('#deviceName').val().trim())  serverData1.deviceName= jQuery('#deviceName').val();else serverData1.deviceName=null;
		if(jQuery('#projectName1').val().trim())  serverData1.projectName= jQuery('#projectName1').val();else serverData1.projectName=null;
		if(jQuery('#type').val().trim()) 	serverData1.type= jQuery('#type').val();else serverData1.type=null;
		if(jQuery('#material').val().trim()) 	serverData1.material= jQuery('#material').val();else serverData1.material=null;
		if(jQuery('#unit').val().trim()) 	 serverData1.unit= jQuery('#unit').val();else serverData1.unit=null;
		
		if(jQuery('#amount').val().trim()) 	 serverData1.amountStartNum= jQuery('#amount').val();else serverData1.amountStartNum=null;
		if(jQuery('#amount-end').val().trim()) 	 serverData1.amountEndNum= jQuery('#amount-end').val();else serverData1.amountEndNum=null;

		if(jQuery('#price').val().trim()) 	 serverData1.priceStartNum= jQuery('#price').val();else serverData1.priceStartNum=null;
		if(jQuery('#price-end').val().trim()) 	 serverData1.priceEndNum= jQuery('#price-end').val();else serverData1.priceEndNum=null;

		if(jQuery('#userName1').val().trim()) 	 serverData1.userName= jQuery('#userName1').val();else serverData1.userName1=null;
		if(jQuery('#superiorArea1').val().trim()) 	 serverData1.superiorArea= jQuery('#superiorArea1').val();else serverData1.superiorArea=null;
		if(jQuery('#replacementCreateTimeStartDate').val().trim()) 	 serverData1.createTimeStartDate= jQuery('#replacementCreateTimeStartDate').val();else serverData1.replacementCreateTimeStartDate=null;
		if(jQuery('#replacementCreateTimeEndDate').val().trim()) 	serverData1.createTimeEndDate= jQuery('#replacementCreateTimeEndDate').val();else serverData1.replacementCreateTimeEndDate=null;
		serverTable1.draw();
//		clearQueryServerData1();
    });
	//清除查询replacement关键字
	var clearQueryServerData1=function(option){

		if(jQuery('#quoteCustomerName').val().trim())  serverData1.customerName= null;
		if(jQuery('#deviceName').val().trim())  serverData1.deviceName= null;
		if(jQuery('#projectName1').val().trim())  serverData1.projectName= null;
		if(jQuery('#type').val().trim()) 	serverData1.type= null;
		if(jQuery('#material').val().trim()) 	serverData1.material= null;
		if(jQuery('#unit').val().trim()) 	 serverData1.unit= null;
		
		if(jQuery('#amount').val().trim()) 	 serverData1.amountStartNum= null;
		if(jQuery('#amount-end').val().trim()) 	 serverData1.amountEndNum= null;

		if(jQuery('#price').val().trim()) 	 serverData1.priceStartNum= null;
		if(jQuery('#price-end').val().trim()) 	 serverData1.priceEndNum= null;

		if(jQuery('#userName1').val().trim()) 	 serverData1.userName= null;
		if(jQuery('#superiorArea1').val().trim()) 	 serverData1.superiorArea= null;
		if(jQuery('#replacementCreateTimeStartDate').val().trim()) 	 serverData1.createTimeStartDate= null;
		if(jQuery('#replacementCreateTimeEndDate').val().trim()) 	serverData1.createTimeEndDate= null;
		if(option=='clearui') jQuery('input').val('');
	}
	// 撤销查询
	jQuery('.resetReplaceBtn').on('click', function() {
		jQuery('#replacekeyword').val();
		clearQueryServerData1('clearui');
		serverTable1.draw();
	});
	var serverData1 = {};
	serverData1.key = '';
	var serverTable1;
	jQuery(document).ready(function() {
						serverTable1 = jQuery('#otherTable').DataTable(
										{
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/quotesearch/getreplacepage',
												"data" : function(d) {
													return $.extend({}, d,
															serverData1);
												}
											},
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
														data : 'quote.customerName',
														render:function(data,type,full,meta){
															if(data == undefined){
																return '<font title=" ">'+'</font>';
															}else{
																return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"...</div>"
															}
														}
													},
													{
														data : 'deviceName',
														render:function(data,type,full,meta){
															return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : null,
														render : function(data,type, full,meta) {
																if (data.quote!=null)
																	//return '<font title="'+data.quote+'">'+data.quote.substring(0,10)+'...'+'</font>';
																	return data.quote.name;
																else if(data.quoteForeign!=null)
																	return data.quoteForeign.name;
														}
													},
													{
														data : 'type',
														render:function(data,type,full,meta){
															return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : 'material',
														render:function(data,type,full,meta){
															return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : 'unit',
														render:function(data,type,full,meta){
															return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
															//return "<div title='"+data+"' style='overflow:hidden; text-overflow:ellipsis; white-space:nowrap;'>"+data+"</div>"
														}
													},
													{
														data : 'amount'
													},
													{
														data : 'price'
													},
													{
														data : null,
														render : function(data) {
																if (data.quote)
																	return data.quote.user.empLogin.userName;
																else if(data.quoteForeign)
																	return data.quoteForeign.user.empLogin.userName;
														}
													},

													{
														data : null,
														render : function(data,type, full,meta) {
																if (data.quote!=null)
																	return data.quote.user.saleArea.superiorArea;
																else if(data.quoteForeign!=null)
																	return data.quoteForeign.user.saleArea.superiorArea;
														}
													} ,
													{
														data : null,
														render : function(data) {
																if (data.quote)
																	return moment(data.quote.createTime).format('YYYY/MM/DD');
																else if(data.quoteForeign)
																	return moment(data.quoteForeign.createTime).format('YYYY/MM/DD');
														}
													},
												],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length
														+ oSettings._iDisplayStart;
												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$(
															'td:eq(0)',
															oSettings.aoData[oSettings.aiDisplay[k]].nTr)
															.text(i + 1);
													k++;
												}
											}
										});
	}); 
           
				

})();